extends StateBase


var enemy01:Enemy01

func enterState(ownerNode):
	$IdleDurationTimer.wait_time = randf_range(1, 2)
	$IdleDurationTimer.start()
	
	
func exitState(ownerNode):
	pass
	
	
func process(delta, ownerNode):
	pass
	
	
func physicsProcess(delta, ownerNode):
	if not enemy01:
		enemy01 = ownerNode as Enemy01
		
	enemy01.animations.play("Idle")
	enemy01.velocity.y += enemy01.gravity * enemy01.gravityScale * delta
	enemy01.velocity.x = 0
		
	var player = get_tree().get_first_node_in_group("Player") as PlayerScript
	var distance2Player = player.global_position.distance_to(enemy01.global_position)
	var dir = sign(player.global_position.x - enemy01.global_position.x) 
	
	if distance2Player <= enemy01.CHASE_DISTANCE:
		stateMachine.changeState("StateChase", ownerNode)
		$IdleDurationTimer.stop()
	elif $IdleDurationTimer.time_left <= Global.EPSILON: 
		stateMachine.changeState("StateSearch", ownerNode)
		
	enemy01.move_and_slide()
		

